import pymongo
import logging

import pytest

from connect_data_src import ConnectDataSource


class ConnectionMongo(ConnectDataSource):
    def __init__(self):
        # 连接mongo
        self.coll = super().connect_mongo()
        self.logger = logging.getLogger(__name__)

    def query_mongo(self, customer_id):
        myquery = {"customer_id": customer_id}
        result = self.coll.find_one(myquery)
        if result is None:
            # print("无符合条件的记录")
            self.logger.info(f"customer_id={customer_id},无符合条件的记录")
        else:
            # print("查询成功")
            self.logger.info(f"有customer_id={customer_id}的数据，{result}")
        return result

    def delete_mongo_one(self, customer_id):
        # 删除一条数据
        mydelete = {"customer_id": customer_id}
        print(mydelete)
        self.coll.delete_one(mydelete)

